$(function(){
});

function changeVc(){
	$('.vcimg').attr('src','/cloud_ifw/common/verify_graphCode.action?_dc' + Math.random());
}

var get_mobile_code_ing = false;
function get_mobile_code() {
	if(get_mobile_code_ing)
		return;
	if(time_verify_code > 0)
		return;
	get_mobile_code_ing = true;
	var userName = $('#userName').val();
	if(!userName) {
		alert('请输入需要找回的用户名或注册手机号');
		return;
	}
	$.getJSON('/cloud_ifw/member/memberbrow_getmobilecodebyusername.action', {
		userName: userName
	}, function(data) {
		if(data.success && data.result) {
			time_verify_code = 60;
			set_time_verify_code();
			alert('验证码已发送');
		} else {
			alert(data.result.errors?data.result.errors:'获取验证码失败');
		}
		get_mobile_code_ing = false;
	});
}

var time_verify_code = 0;
function set_time_verify_code() {
	setTimeout(function() {
		if(time_verify_code > 0) {
			time_verify_code -= 1;
			$('#get_mobile_code').addClass('timeing');
			$('#get_mobile_code').attr('disabled', 'disabled');
			$('#get_mobile_code').html(time_verify_code + '秒后可重新获取');
			set_time_verify_code();
		} else {
			// 倒计时结束
			$('#get_mobile_code').removeClass('timeing');
			$('#get_mobile_code').removeAttr('disabled');
			$('#get_mobile_code').html('获取验证码');
		}
	}, 1000);
}

function register_ok(){
	var userName = $('#userName').val();
	if(!userName) {
		alert('请输入用户名');
		return;
	}
	var password = $('#password').val();
	if(!password) {
		alert('请输入密码');
		return;
	}
	var password2 = $('#password2').val();
	if(!password2) {
		alert('请输入确认密码');
		return;
	}
	if(password != password2) {
		alert('密码和确认密码不一致');
		return;
	}
	var mobileCode = $('#mobileCode').val();
	if(!mobileCode) {
		alert('请输入手机验证码');
		return;
	}
	var verifyCode = $('#verifyCode').val();
	if(!verifyCode) {
		alert('请输入验证码');
		return;
	}
	var url = '/cloud_ifw/member/memberbrow_forgetpwd.action';
	var data = {
		userName: userName,
		password: password,
		password2: password2,
		mobileCode: mobileCode,
		verifyCode: verifyCode
	};
	$.post(url, data, function(r) {
		var data = $.parseJSON(r);
		if(data.success && data.result) {
			alert('修改成功');
			location.href = 'login.jsp';
		} else {
			alert(data.result.errors?data.result.errors:'修改失败');
		}
	});
}